#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#*===========================================================================*/
#*                                                                           */
#* Module Name:  ctfirst                                                     */
#*                                                                           */
#* Description:                                                              */
#*      Script to invoke one time configuration commands the first           */
#*      time the RMC subsystem is started after installation.                */
#*                                                                           */
#* N.B. This command is intended to be executed by the RMC subsystem only !! */
#*                                                                           */
#*===========================================================================*/
#*   @(#)57   1.2   src/rsct/rmc/mcdaemon/ctfirst.sh, mcdaemon, rsct_rpyxh, rpyxht1f3 10/10/00 23:43:57 

PATH=/usr/sbin/rsct/install/bin:/usr/sbin/rsct/bin:/usr/bin:/usr/sbin:/bin
export PATH

FIRST=/var/ct/first_start
FIRSTDIR=/usr/sbin/rsct/install/first

print "Process ID of ctfirst is $$"

#============================================================================
#
# Wait for the RMC subsystem to come up
#
#============================================================================

RETRY_LIMIT=10		# number of 2 second retry intervals (20 second total)

let i=$RETRY_LIMIT

while :
do
	lsrsrc > /dev/null 2>&1
	rc=$?
	if [[ $rc -eq 0 ]]
	then
		break
	fi

	i=$((i - 1))

	if (( i > 0 ))
	then
		sleep 2
	else
		break
	fi
done

if [[ $rc -ne 0 ]]
then
	print "RMC subsystem has not started"
	exit 1
fi

#============================================================================
#
# Execute one time configuration commands
#
#============================================================================

cmds_failed=0

cmd_list=$(ls $FIRSTDIR/* 2> /dev/null)
if [[ -z "$cmd_list" ]]
then
	print "No one time configuration commands found"
else
	for cmd in $cmd_list
	do
		if [[ -f $cmd && -x $cmd ]]
		then
			print "\n============ Executing $cmd ============"
			$cmd
			rc=$?
			print "============ $cmd exited with $rc ============"
			if [[ $rc -ne 0 ]]
			then
				cmds_failed=1
			fi
		else
			print "$cmd is not executable; it is ignored"
		fi
	done
fi

if [[ $cmds_failed -eq 0 ]]
then
	print "Removing $FIRST"
	rm -f $FIRST
fi
